package com.example.administrator.szb.activity.luyan.presenter;

import com.alibaba.fastjson.JSON;
import com.example.administrator.szb.activity.base.BasePresenter;
import com.example.administrator.szb.activity.luyan.model.MyLuyanModelImpl;
import com.example.administrator.szb.activity.luyan.view.MyLuyanView;
import com.example.administrator.szb.fragments.fragment_forTab.home.bean.LuYanList;
import com.example.administrator.szb.http.OnResultListener;
import com.example.administrator.szb.util.SPUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by stone on 2018/1/29.
 */

public class MyLuyanPresenter extends BasePresenter<MyLuyanView> implements OnResultListener{
    MyLuyanModelImpl myLuyanModel;
    MyLuyanView myLuyanView;

    public MyLuyanPresenter(MyLuyanView myLuyanView) {
        this.myLuyanView = myLuyanView;
        myLuyanModel = new MyLuyanModelImpl();
    }
    public void getAll(int page,int page_count,int type){
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("page_count",page_count);
        map.put("uid",""+ SPUtils.getUserId());
        if (type==0){//我发布的

            myLuyanModel.getALl(activity,map,this);
        }else if (type==1){//我报名的

            myLuyanModel.getMyAll(activity,map,this);
        }else {//所有的
            map.put("uid","0");
            myLuyanModel.getALl(activity,map,this);
        }
    }

    @Override
    public void onSuccess(int requestCode, String str) {
        myLuyanView.showList(JSON.parseArray(str, LuYanList.class));
    }

    @Override
    public void onFailure(int requestCode, String str) {
        myLuyanView.onFails(str);
    }
}
